/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package oop.demo.restaurantmanagementsystem;

/**
 * Meal class for managing meals composed of ingredients
 * name: the meals name
 * Ingredients: list of ingrdients
 * @author ashongtical
 */

import java.util.ArrayList;

public class Meal implements Priceable {
    private String name;
    private ArrayList<Ingredient> Ingredients;
    
    public Meal(String name){
        this.name = name;
        this.Ingredients = new ArrayList<>();
    }
    
    public String getName(){
        return this.name;
    }
    
    public void addIngredient(Ingredient ingredient){
        this.Ingredients.add(ingredient);
    }
    
    public ArrayList<Ingredient> getIngredients(){
        return Ingredients;
    }
    
    @Override
    public double getPrice(){
        double total = 0.0;
        for(Ingredient ingredient : Ingredients){
            total += ingredient.getPrice();
        }
        return total;
    }
    
    @Override
    public String toString(){
        String md = name + "(RMB" + getPrice() + ") [";
        for(Ingredient ingredient : Ingredients){
            md += "" + ingredient.getName() + ",";
        }
        if(Ingredients.size() > 0){
            md = md.substring(0,md.length() - 1);
        }
        
        md += "]";
        return md.toString();
        
    }
}
